/*

pgm:  02_create_survey_files_d_n_20210212

Purpose: This program creates survey files for the voting project.

This program converts SAS MTO data provided to Census Bureau to stata and adds on 
anonymized IDs for voting project.

Keeps select variables per voting project request 

*/

********************************************
* 1. set globals
********************************************

macro drop _all

cap log close
clear
set type double
global today 20210212

cap log close
log using "~/mtoproj/m10_data/external_researchers/mendelberg/logs/02_create_survey_files_d_to_j_$today.log", text replace


/* input files */
global outxwlk2  "~/mtoproj/m10_data/external_researchers/mendelberg/mto_ids/mto_voter_xwalk2.dta"
*global wgtplus "~/mtoproj/m10_data/svy_analysis/wgtcov/mto_fnl_wgts_20120413plus.dta"
global archdir "~/mtoproj/m10_data/papers/census_archive/from_transport/"

global arc_blh "${archdir}mto_bascnv_hhld.sas7bdat"
global arc_blp "${archdir}mto_bascnv_pers.sas7bdat"

global arc_irawad "${archdir}mto_int_rawsvy_adult.sas7bdat"
global arc_irawyt "${archdir}mto_int_rawsvy_youth.sas7bdat"
global arc_irawro "${archdir}mto_int_roster.sas7bdat"

global arc_frawad "${archdir}mto_fin_rawsvy_adult.sas7bdat"
global arc_frawyt "${archdir}mto_fin_rawsvy_youth.sas7bdat"
global arc_frawro "${archdir}mto_fin_roster.sas7bdat"

global arc_intaad "${archdir}mto_int_anly_adult.sas7bdat"
global arc_intachyt "${archdir}mto_int_anly_childyth.sas7bdat"

global arc_fina "${archdir}mto_fin_analysis.sas7bdat"
global arc_finr "${archdir}mto_fin_roster.sas7bdat"



/* output dirs */
// actual MTO study IDs
global dir_mto_id "~/mtoproj/m10_data/external_researchers/mendelberg/mto_ids/"
// pseudo IDs for voting project
global dir_pseudo_id "~/mtoproj/m10_data/external_researchers/mendelberg/pseudo_ids/"

/* output files */
// family crosswalk
global outfamxwlk  "~/mtoproj/m10_data/external_researchers/mendelberg/mto_ids/mto_voter_famxwlk.dta"

// baseline household 
global outblh_id  "${dir_mto_id}/d_mto_base_hhld_ids.dta"
global outblh_pseudo  "${dir_pseudo_id}/d_mto_base_hhld_pseudo.dta"

// baseline person
global outblp_id  "${dir_mto_id}/e_mto_base_pers_ids.dta"
global outblp_pseudo  "${dir_pseudo_id}/e_mto_base_pers_pseudo.dta"

// interim adult raw survey data
global outirawad_id  "${dir_mto_id}/f_mto_int_rawsvy_ad_ids.dta"
global outirawad_pseudo  "${dir_pseudo_id}/f_mto_int_rawsvy_ad_pseudo.dta"

// interim youth raw survey data - NOT USED
global outirawyt_id  "${dir_mto_id}/g_mto_int_rawsvy_yt_ids.dta"
global outirawyt_pseudo  "${dir_pseudo_id}/g_mto_int_rawsvy_yt_pseudo.dta"

// final adult raw survey data
global outfrawad_id  "${dir_mto_id}/h_mto_fin_rawsvy_ad_ids.dta"
global outfrawad_pseudo  "${dir_pseudo_id}/h_mto_fin_rawsvy_ad_pseudo.dta"

// final youth raw survey data
global outfrawyt_id  "${dir_mto_id}/i_mto_fin_rawsvy_yt_ids.dta"
global outfrawyt_pseudo  "${dir_pseudo_id}/i_mto_fin_rawsvy_yt_pseudo.dta"

// final roster data
global outfrawro_id  "${dir_mto_id}/j_mto_fin_roster_ids.dta"
global outfrawro_pseudo  "${dir_pseudo_id}/j_mto_fin_roster_pseudo.dta"

// interim adult analysis file 
global outintaad_id  "${dir_mto_id}/k_mto_int_adult_analysis_ids.dta"
global outintaad_pseudo  "${dir_pseudo_id}/k_mto_int_adult_analysis_pseudo.dta"

// interim child youth analysis file 
global outintachyt_id  "${dir_mto_id}/l_mto_int_adult_analysis_ids.dta"
global outintachyt_pseudo  "${dir_pseudo_id}/l_mto_int_adult_analysis_pseudo.dta"

// interim roster file 
global outirawro_id  "${dir_mto_id}/m_mto_int_roster_ids.dta"
global outirawro_pseudo  "${dir_pseudo_id}/m_mto_int_roster_pseudo.dta"

// final analysis file
global outfina_id  "${dir_mto_id}/n_mto_fin_analysis_ids.dta"
global outfina_pseudo  "${dir_pseudo_id}/n_mto_fin_analysis_pseudo.dta"


#delimit ;



/*
. ls
total 79390
-rw-r--r-- 1 lsanbonm mtoproj  11841536 Apr 20  2017 mto_bascnv_hhld.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj  91607040 Apr 20  2017 mto_fin_analysis.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj  40378368 Apr 20  2017 mto_fin_rawsvy_adult.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj  51351552 Apr 20  2017 mto_fin_rawsvy_youth.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj  26095616 Apr 20  2017 mto_fin_roster.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj  10588160 Apr 20  2017 mto_int_anly_adult.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj  22282240 Apr 20  2017 mto_int_anly_childyth.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj  10813440 Apr 20  2017 mto_bascnv_pers.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj  17563648 Apr 20  2017 mto_int_rawsvy_adult.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj   1179648 Apr 20  2017 mto_int_rawsvy_child.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj   4718592 Apr 20  2017 mto_int_rawsvy_pocy.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj   8638464 Apr 20  2017 mto_int_rawsvy_youth.sas7bdat
-rw-r--r-- 1 lsanbonm mtoproj   7733248 Apr 20  2017 mto_int_roster.sas7bdat

*/;

/*

	global ${abbr}_req_150 "Race";
	 global ${abbr}_var_150 unknown;


	global ${abbr}_req_57 "Year 1st child was born [no variable ID available. item appears on Adult Information Form from Part II  Household Information]  baseline survey";
	 global ${abbr}_var_57 donotprovide;

	 global ${abbr}_req_78 "";
	 global ${abbr}_var_78 header;
	global ${abbr}_req_79 "Crime Exposure";
	 global ${abbr}_var_79 header;
* address history - not providing * ;
	global ${abbr}_req_119 "HHC4_1_ORIG: Where did you live before you lived at [previous address]?  final household evaluation";
	 global ${abbr}_var_119 unknown;
	global ${abbr}_req_120 "HHC4a_1_ORIG: Where did you live before you lived at [address]?  final household evaluation";
	 global ${abbr}_var_120 unknown;
	global ${abbr}_req_121 "HHC4c_1_ORIG: What is the nearest intersection by that address?  final household evaluation";
	 global ${abbr}_var_121 unknown;
	global ${abbr}_req_122 "HHC5a_1_ORIG: Where did you live before you lived at [previous address]?  final household evaluation";
	 global ${abbr}_var_122 unknown;
	global ${abbr}_req_123 "HHC5b_1_ORIG: What is the nearest intersection by that address?  final household evaluation";
	 global ${abbr}_var_123 unknown;
	global ${abbr}_req_124 "HHC6_1_ORIG: In what year did you move from that address?  final household evaluation";
	 global ${abbr}_var_124 unknown;
	global ${abbr}_req_125 "HHC8_A5_MTOm: During the time between when you lived at [previous address] and [this address], we would like to know if there was a time when you did not have your own place to stay?  final household evaluation";
	 global ${abbr}_var_125 unknown;
	global ${abbr}_req_126 "HHC10a_A6e_MTOm: At that time were your children living with you, or living somewhere else?  final household evaluation";
	 global ${abbr}_var_126 unknown;
	global ${abbr}_req_127 "HHC10b_1_ORIG: How long were you without a place of your own (number)?  final household evaluation";
	 global ${abbr}_var_127 unknown;
	global ${abbr}_req_128 "HHC10c_1_ORIG: How long were you without a place of your own (unit of measurement)?  final household evaluation";
	 global ${abbr}_var_128 unknown;

* Adding * ;
	global ${abbr}_req_155 "survey weights";
	 global ${abbr}_var_155 unknown;
	global ${abbr}_req_156 "aa";
	 global ${abbr}_var_156 unknown;
	global ${abbr}_req_157 "bb";
	 global ${abbr}_var_157 unknown;
	global ${abbr}_req_158 "cc";
	 global ${abbr}_var_158 unknown;
	global ${abbr}_req_159 "dd";
	 global ${abbr}_var_159 unknown;

	 
* source not known * ;
	global ${abbr}_req_141 "Non-Survey Items";
	 global ${abbr}_var_141 unknown;
	global ${abbr}_req_142 "Number of people living in household at baseline";
	 global ${abbr}_var_142 unknown;
	global ${abbr}_req_143 "Whether the respondent is the head of household";
	 global ${abbr}_var_143 unknown;
	global ${abbr}_req_146 "Unique family ID";
	 global ${abbr}_var_146 mtofamid;

	 
* from weight file	 
 	global ${abbr}_req_145 "Sample site/city";
	 global ${abbr}_var_145 ra_site;
	 global ${abbr}_req_147 "Experimental condition that the family was randomly assigned to";
	global ${abbr}_var_147 ra_group;
	global ${abbr}_req_148 "Compliance with randomly assigned condition";
	 global ${abbr}_var_148 f_svy_cmove;
	global ${abbr}_req_149 "Duration of time in new neighborhood/moving frequency since random assignment";
	 global ${abbr}_var_149 unknown;
	global ${abbr}_req_151 "Gender";
	 global ${abbr}_var_151 f_svy_gender;
	global ${abbr}_req_152 "Ethnicity";
	 global ${abbr}_var_152 unknown;
	global ${abbr}_req_153 "Age";
	 global ${abbr}_var_153 unknown;
	global ${abbr}_req_154 "Weighting variables";
	 global ${abbr}_var_154 unknown;
	global ${abbr}_req_144 "Year of random assignment";
	 global ${abbr}_var_144 ra_year;
	global ${abbr}_req_160 "interim disposition";
	 global ${abbr}_var_160 unknown;
	global ${abbr}_req_161 "final disposition";
	 global ${abbr}_var_161 unknown;
	global ${abbr}_req_162 "sample type";
	 global ${abbr}_var_162 unknown;
	 	 
	 
* headers * ;
	global ${abbr}_req_2 "Educational Attainment";
	 global ${abbr}_var_2 header;
	global ${abbr}_req_24 "";
	 global ${abbr}_var_24 header;
	global ${abbr}_req_25 "Income and Employment";
	 global ${abbr}_var_25 header;
	global ${abbr}_req_42 "";
	 global ${abbr}_var_42 header;
	global ${abbr}_req_43 "AFDC and Other Benefits";
	 global ${abbr}_var_43 header;
	global ${abbr}_req_49 "";
	 global ${abbr}_var_49 header;
	global ${abbr}_req_50 "Marital Status";
	 global ${abbr}_var_50 header;
	global ${abbr}_req_55 "";
	 global ${abbr}_var_55 header;
	global ${abbr}_req_56 "Parental Status";
	 global ${abbr}_var_56 header;
	global ${abbr}_req_61 "";
	 global ${abbr}_var_61 header;
	global ${abbr}_req_62 "Time in Jail/Prison";
	 global ${abbr}_var_62 header;
	global ${abbr}_req_66 "";
	 global ${abbr}_var_66 header;
	global ${abbr}_req_67 "Social Connection";
	 global ${abbr}_var_67 header;
	global ${abbr}_req_93 "";
	 global ${abbr}_var_93 header;
	global ${abbr}_req_94 "Perceived Racial Discrimination";
	 global ${abbr}_var_94 header;
	global ${abbr}_req_98 "";
	 global ${abbr}_var_98 header;
	global ${abbr}_req_99 "Satisfaction with Neighborhood";
	 global ${abbr}_var_99 header;
	global ${abbr}_req_103 "";
	 global ${abbr}_var_103 header;
	global ${abbr}_req_104 "Under-Served by Police";
	 global ${abbr}_var_104 header;
	global ${abbr}_req_106 "";
	 global ${abbr}_var_106 header;
	global ${abbr}_req_107 "Moving Frequency, Housing Stability, Housing History, and Moving Information";
	 global ${abbr}_var_107 header;
	global ${abbr}_req_129 "";
	 global ${abbr}_var_129 header;
	global ${abbr}_req_130 "Child Well Being Index";
	 global ${abbr}_var_130 header;
	global ${abbr}_req_139 "";
	 global ${abbr}_var_139 header;
	global ${abbr}_req_140 "";
	 global ${abbr}_var_140 header;

*/;	 
	 
	 
***********************************;
* BASELINE HHLD VARIABLES              *;
***********************************;	 
 
global abbr blh; 
 
* baseline hhld form *;
	global ${abbr}_req_26 "Section 4, Item 6: How much do you usually earn an hour?  baseline survey";
	 global ${abbr}_var_26 mnwagehr mnnowrk2;
	global ${abbr}_req_27 "Section 4, Item 7: How many hours do you usually earn in a week  baseline survey";
	 global ${abbr}_var_27 mnhrswek mnnowrk3;
	global ${abbr}_req_28 "Section 4, Item 18: Do you have a car that runs?  baseline survey";
	 global ${abbr}_var_28 mncar;
	global ${abbr}_req_44 "Section 5, Item 2: Are you getting AFDC (welfare) now?  baseline survey";
	 global ${abbr}_var_44 mnafdcnw;
	global ${abbr}_req_45 "Section 5, Item 7A: Do you now get food stamps  baseline survey";
	 global ${abbr}_var_45 mnfdstmp;

	global ${abbr}_req_46 "Section 5, Item 8: Is there anyone living with you who has a health problem or mental problem that keeps him/her from doing normal activities like walking, getting dressed, housework, or working?  baseline survey";
	 global ${abbr}_var_46 mndisabl;
	 global ${abbr}_req_68 "Section 3, Item 5: How often do you stop to chat with a neighbor in the street or hallway?  baseline survey";
	 global ${abbr}_var_68 mnchat;
	global ${abbr}_req_69 "Section 3, Item 6: How many of your friends live in the same neighborhood as you?  baseline survey";
	 global ${abbr}_var_69 mnfrends;
	global ${abbr}_req_70 "Section 3, Item 7: How many of your family members live in the same neighborhood as you?  baseline survey";
	 global ${abbr}_var_70 mnfamily;
	global ${abbr}_req_71 "Section 3, Item 8: If you saw a neighbor’s child getting into trouble, how likely is it that you would tell your neighbor about it?";
	 global ${abbr}_var_71 mnnbrkid;

	 global ${abbr}_req_80 "Section 2, Item 5: How safe are the streets near your home at night?  baseline survey";
	 global ${abbr}_var_80 mnstrtnt;

	 global ${abbr}_req_81 "Section 2, Item 12A: (In the past 6 months), was anyone’s purse, wallet, or jewelry snatched from them?  baseline survey";
	 global ${abbr}_var_81 mnsnatch;
	 
	global ${abbr}_req_82 "Section 2, Item 12B: (In the past 6 months), was anyone threatened with a knife or gun?  baseline survey";
	 global ${abbr}_var_82 mnthreat;
	global ${abbr}_req_83 "Section 2, Item 12C: (In the past 6 months), was anyone beaten or assaulted?  baseline survey";
	 global ${abbr}_var_83 mnbeaten;
	global ${abbr}_req_84 "Section 2, Item 12D: (In the past 6 months), was anyone stabbed or shot?  baseline survey";
	 global ${abbr}_var_84 mnstabbd;
	global ${abbr}_req_85 "Section 2, Item 12E: (In the past 6 months), did anyone try to break into your home?  baseline survey";
	 global ${abbr}_var_85 mnbreakn;
	global ${abbr}_req_100 "Section 2, Item 1: Which of the following statements best describes how satisfied you are with your neighborhood?  baseline survey";
	 global ${abbr}_var_100 mnsatisf;


	 
	 global ${abbr}_req_108 "Section 1, Item 1: Have you ever applied for a Section 8 voucher or certificate before today?  baseline survey";
	 global ${abbr}_var_108 mnappld;
	global ${abbr}_req_109 "Section 1, Item 2: How long have you lived in your apartment or house?  baseline survey";
	 global ${abbr}_var_109 mnapt_yr mnapt_mo;
	global ${abbr}_req_110 "Section 1, Item 4: Have you moved more than three times in the past five years?  baseline survey";
	 global ${abbr}_var_110 mnmov3tm;
	global ${abbr}_req_111 "Section 1, Item 9: What is the main reason you want to move?  baseline survey";
	 global ${abbr}_var_111 mnwhymv1;
	global ${abbr}_req_112 "Section 1, Item 10: What is the second most important reason you want to move?  baseline survey";
	 global ${abbr}_var_112 mnwhymv2;
	global ${abbr}_req_113 "Section 6, Item 1: How sure are you that you will be able to find an apartment in a different area of [the city]?  baseline survey";
	 global ${abbr}_var_113 mnfndapt;

	 
	 
***********************************;
* BASELINE PERSON VARIABLES              *;
***********************************;	 


global abbr blp; 

 
* baseline adult info form * ;
	global ${abbr}_req_3 "Is this person now in school? [no variable ID available item appears on Adult Information Form from Part II  Household Information]  baseline survey";
	 global ${abbr}_var_3 adinschl;
	global ${abbr}_req_4 "Graduated from high school or GED? [no variable ID available item appears on Adult Information Form from Part II  Household Information]  baseline survey";
	 global ${abbr}_var_4 adgrad;
	global ${abbr}_req_51 "Martial status [no variable ID available item appears on Adult Information Form from Part II  Household Information]  baseline survey";
	 global ${abbr}_var_51 admarstt;
	global ${abbr}_req_29 "Now working full or part time? [no variable ID available item appears on Adult Information Form from Part II  Household Information]  baseline survey";
	 global ${abbr}_var_29 adworkfp;

	 
* baseline child 0-5 info form * ;

	global ${abbr}_req_136 "How much did this child weigh when he/she was born? [no variable ID available Item 3 under the Children in Household Ages 5 and Younger section]  baseline survey";
	 global ${abbr}_var_136 c2weighp c2weigho c2dontk ;
	 
	global ${abbr}_req_137 "Was this child ever in the hospital before his/her first birthday because this child was sick or injured? [no variable ID available Item 4 under the Children in Household Ages 5 and Younger section]  baseline survey";
	 global ${abbr}_var_137 c2hosp;
	 
	global ${abbr}_req_138 "How often do you or someone in your home have a chance to read a book or story to this child? [no variable ID available Item 11A under the Children in Household Ages 5 and Younger section]  baseline survey";
	 global ${abbr}_var_138 c2rdbook;


* baseline child 6-17 info form * ;
	 
	global ${abbr}_req_5 "Is this child now in school? [no variable ID available Item 3 under the Children in Household Ages 6 to 17 section]  baseline survey";
	 global ${abbr}_var_5 c1kidsch;
	global ${abbr}_req_131 "Does this child have any physical, emotional, or mental problems that (a) means this child needs special medicine or equipment? (b) makes it hard for this child to get to school? (c) makes it hard for this child to play active games or sports? Is this child now in school? [no variable IDs available. Items 8A, 8B, and 8C under the "Children in Household Ages 6 to 17" section]  baseline survey";
	global ${abbr}_var_131 c1ch6ds1 c1ch6ds2 c1ch6ds3;
	global ${abbr}_req_132 "During the past two years, has this child ever been suspended or expelled from school? [no variable ID available. Item 9 under the "Children in Household Ages 6 to 17" section]  baseline survey";
	 global ${abbr}_var_132 c1suspnd;
	global ${abbr}_req_133 "During the past two years, has this child gone to a special class or school or gotten special help in school for (a) learning problems? (b) behavioral or emotional problems? [no variable IDs available. Items 7A and 7B under the Children in Household Ages 6 to 17 section]  baseline survey";
	 global ${abbr}_var_133 c1splrn c1spbehv;
	global ${abbr}_req_134 "Does this child go to a special class for gifted students or do advanced work in any subjects? [no variable ID available Item 6 under the Children in Household Ages 6 to 17 section]  baseline survey";
	 global ${abbr}_var_134 c1spclss;
	global ${abbr}_req_135 "During the past two years, has anyone from this child’s school asked someone to come in and talk about problems this child was having with schoolwork or behavior? [no variable ID available Item 10 under the Children in Household Ages 6 to 17 section]  baseline survey";
	 global ${abbr}_var_135 c1schcll;

	 
	 
***********************************;
* HOUSEHOLD FINAL *;
***********************************;	 

global abbr frawad; 
	 
* household final * ;
	global ${abbr}_req_12 "HED1_B1_MTO: What is the highest grade or year of regular school that you have completed and gotten credit for?  final household evaluation";
	 global ${abbr}_var_12 hed1;
	 
	global ${abbr}_req_13 "HED2_B2_MTO: Do you have a high school diploma or GED?  final household evaluation";
	 global ${abbr}_var_13 hed2;
	 
	global ${abbr}_req_14 "HED3_1_ORIG: Do you have a college degree?  final household evaluation";
	 global ${abbr}_var_14 hed3;
	 
	global ${abbr}_req_15 "HED4_1_ORIG: What is the highest degree you have received?  final household evaluation";
	 global ${abbr}_var_15 hed4;

	global ${abbr}_req_52 "HRL1_1_FFm: Are you currently married, in a romantic relationship, or not currently in a relationship?  final household evaluation";
	 global ${abbr}_var_52 HRL1;
	 
	global ${abbr}_req_72 "HSN20_E5_MTO: During the past thirty days, about how often have you had close friends over to your home?  final household evaluation";
	 global ${abbr}_var_72 HSN20;
	 
	global ${abbr}_req_73 "HSN21_E6_MTO: During the past thirty days about how often have you visited with close friends at their homes?  final household evaluation";
	 global ${abbr}_var_73 HSN21;
	 
	global ${abbr}_req_74 "HSN31_E14_MTO: In the past 12 months, how often have you gone to church or attended other religious services?  final household evaluation";
	 global ${abbr}_var_74 HSN31;
	 
	global ${abbr}_req_86 "HNB3_A13_MTO: Have you seen people using or selling illegal drugs in your neighborhood during the past 30 days?  final household evaluation";
	 global ${abbr}_var_86 HNB3;
	 
	global ${abbr}_req_87 "HNB9b_19b_MTO: How safe do you feel on the streets near your home at night?  final household evaluation";
	 global ${abbr}_var_87 HNB9b;
	 
	global ${abbr}_req_88 "HNB2a_A12a_MTO: In your neighborhood, how big of a problem is litter or trash on the streets or sidewalk?  final household evaluation";
	 global ${abbr}_var_88 HNB2a;
	 
	global ${abbr}_req_89 "HNB2b_A12b_MTO: (In your neighborhood,) how big of a problem is graffiti or writing on the walls?  final household evaluation";
	 global ${abbr}_var_89 HNB2b;
	 
	global ${abbr}_req_90 "HNB2d_A12d_MTO: (In your neighborhood, how big of a problem is) abandoned buildings?  final household evaluation";
	 global ${abbr}_var_90 HNB2d;
	 
	global ${abbr}_req_95 "HNB6b_A15b_MTO: Can you think of one or more occasions in the last 6 months when you felt you were treated unfairly because of your race or ethnicity in your own neighborhood?  final household evaluation";
	 global ${abbr}_var_95 HNB6b;
	 
	global ${abbr}_req_96 "HNB6d_A15d_MTO: Can you think of one or more occasions in the last 6 months when you felt you were treated unfairly because of your race or ethnicity in dealing with the police, such as a traffic accident?  final household evaluation";
	 global ${abbr}_var_96 HNB6d;
	 
	global ${abbr}_req_101 "HNB1_A11_MTO: Which of the following statements best describes how satisfied you are with your neighborhood?  final household evaluation";
	 global ${abbr}_var_101 HNB1;
	 
	global ${abbr}_req_105 "HNB2f_A12f_MTO: (In your neighborhood, how big of a problem is) police not coming when called?  final household evaluation";
	 global ${abbr}_var_105 HNB2f;

	 
***********************************;
* INTERIM HOUSEHOLD SURVEY *;
***********************************;	 

global abbr irawad; 
	 
* interim * ;
	global ${abbr}_req_6 "B1: What is the highest grade or year of regular school that you have completed or gotten credit for?  interim household survey";
	 global ${abbr}_var_6 B1;
	global ${abbr}_req_7 "B2: Do you have a high school diploma or GED?  interim household survey";
        global ${abbr}_var_7 B2;
	global ${abbr}_req_114 "A6: How many months or years have you lived in your current house/apartment/living space?  interim household survey";
	 global ${abbr}_var_114 A6a A6b;
	global ${abbr}_req_115 "A7: Was there ever a time during the past year when you did not have your own place to stay?  interim household survey";
	 global ${abbr}_var_115 A7;
	global ${abbr}_req_116 "A9: How many months or years has it been since you rented or owned your own unit?  interim household survey";
	 global ${abbr}_var_116 A9a A9b;
	global ${abbr}_req_117 "A10: How many months or years have you lived in your current neighborhood?  interim household survey";
	 global ${abbr}_var_117 A10a A10b;
	global ${abbr}_req_118 "A22: How many times have you moved since the year of random assignment?  interim household survey";
	 global ${abbr}_var_118 A22;


***********************************;
* FINAL ROSTER *;
***********************************;

global abbr frawro; 
* roster * ;
	global ${abbr}_req_63 "HHO10a_1_ORIG: Has [he/she] (ever) spent any time in jail or prison?  final household evaluation";
	 global ${abbr}_var_63 HHO10a;
	global ${abbr}_req_64 "HHO10b_1_ORIG: Do you know approximately how long [he/she] spent in jail or prison?  final household evaluation";
	 global ${abbr}_var_64 HHO10b;
	global ${abbr}_req_65 "HHO10c_1_ORIG: When was the last time [he/she] was in jail or prison?  final household evaluation";
	 global ${abbr}_var_65 HHO10c;
	global ${abbr}_req_16 "HHO3_1_ORIG: Has [member] graduated from high school or have a GED?  final household evaluation";
	 global ${abbr}_var_16 HHO3;
	global ${abbr}_req_17 "HHO4_1_ORIG: Has [he/she] ever attended college or does [he/she] attend college now?  final household evaluation";
	 global ${abbr}_var_17 HHO4;
	global ${abbr}_req_38 "HHO5_1_ORIG: Is [he/she] now working for pay full-time or part-time?  final household evaluation";
	 global ${abbr}_var_38 HHO5;
	global ${abbr}_req_54 "HHO6_G3k_MTO: What is (his/her) marital status?  final household evaluation";
	 global ${abbr}_var_54 HHO6;
	global ${abbr}_req_58 "HHO7_1_ORIG: How many biological children does (he/she) have?  final household evaluation";
	 global ${abbr}_var_58 HHO7;


***********************************;
* FINAL RAW YOUTH SURVEY *;
***********************************;

global abbr frawyt; 

* youth final * ;
	global ${abbr}_req_18 "YED1_S1_MTO: Are you currently attending or enrolled in regular school?  final youth evaluation";
	 global ${abbr}_var_18 YED1;
	global ${abbr}_req_19 "YED2a_S2a_MTO: What grade or year of school are you attending/did you most recently attend?  final youth evaluation";
	 global ${abbr}_var_19 YED2a;
	global ${abbr}_req_20 "YED3a_J1_MTO: What is the highest grade or year of school you have completed?  final youth evaluation";
	 global ${abbr}_var_20 YED3a;
	global ${abbr}_req_21 "YED3c_J2_MTO: Have you received a regular high school diploma?  final youth evaluation";
	 global ${abbr}_var_21 YED3c;
	global ${abbr}_req_22 "YED3c_J3_MTO: Have you received a GED?  final youth evaluation";
	 global ${abbr}_var_22 YED3c;
	global ${abbr}_req_23 "YED3e_S2b_MTO: Are you attending/did you attend a two-year college, four-year college, a trade or business school, or another type of college/school?  final youth evaluation";
	 global ${abbr}_var_23 YED3e;
	global ${abbr}_req_40 "YEM1_T1_MTO: Last week, did you do any work for pay?  final youth evaluation";
	 global ${abbr}_var_40 YEM1;
	global ${abbr}_req_41 "YEM8_T8_MTO: (Including overtime pay, tips, and commissions), what are your usual [daily/biweekly/twice monthly/monthly/annual] earnings on this job, before taxes or other deductions?  final youth evaluation";
	 global ${abbr}_var_41 YEM8;
	global ${abbr}_req_48 "YRB35_U34_MTO: Are you [or your child/or your children] regularly receiving welfare benefits now?  final youth evaluation";
	 global ${abbr}_var_48 YRB35;
	global ${abbr}_req_59 "YHL1e_1_ORIG: Who do you live with? Do you live with your [husband/wife], with your partner, with friends, with other relatives, or with your own or someone else’s children?  final youth evaluation";
	 global ${abbr}_var_59 YHL1e__s_1 YHL1e__s_2 YHL1e__s_3 YHL1e__s_4;
	global ${abbr}_req_60 "YHL1d_1_ORIG: Do you have children of your own who live with you?  final youth evaluation";
	 global ${abbr}_var_60 YHL1d;
	global ${abbr}_req_75 "YSN9a_1_GSSm: How did you meet or come to know your [friend/friends]?  final youth evaluation";
	 global ${abbr}_var_75 YSN9a__s_1 YSN9a__s_2 YSN9a__s_3 YSN9a__s_4 YSN9a__s_5 YSN9a__s_6 YSN9a__s_7 YSN9a__s_8 YSN9a__s_9 ;
	global ${abbr}_req_76 "YSN12_W12a_MTO: During the past year, how often have you visited or spent time with [this friend/these friends] [that you had at the time of random assignment]?  final youth evaluation";
	 global ${abbr}_var_76 YSN12;
	 
	global ${abbr}_req_77 "YSN13_W13_MTO: In the past 12 months, how often did you attend such youth activities [sponsored by a religious organization]?  final youth evaluation";
	 global ${abbr}_var_77 YSN13;
	global ${abbr}_req_91 "YNB6_A13_MTO: Have you seen people using or selling illegal drugs in your neighborhood during the past 30 days?  final youth evaluation";
	 global ${abbr}_var_91 YNB6;
	global ${abbr}_req_92 "YNB3b_A19b_MTO: How safe do you feel on the streets near your home at night?  final youth evaluation";
	 global ${abbr}_var_92 YNB3b;
	global ${abbr}_req_97 "YNB4e_A15_MTO: Can you think of one or more occasions in the last 6 months when you felt you were treated unfairly because of your race or ethnicity in dealing with the police, such as a traffic accident?  final youth evaluation";
	 global ${abbr}_var_97 YNB4e;
	global ${abbr}_req_102 "YNB2_W1_MTO: Which of the following statements best describes how satisfied you are with your neighborhood?  final youth evaluation";
	 global ${abbr}_var_102 YNB2;
	 

***********************************;
* FINAL ANALYSIS FILE *;
***********************************;	 
 
global abbr fina; 

	 global ${abbr}_req_35 "HEM1_C1_MTO: Last week, did you do any work for pay?  final household evaluation";
	 global ${abbr}_var_35 F_EM_EMP_AD;
	 
	 global ${abbr}_req_36 "HEM11_C11_MTO: (Including overtime pay, tips, and commissions), what are your usual [daily/biweekly/twice monthly/monthly/annual] earnings on this job, before taxes or other deductions?  final household evaluation";
	 global ${abbr}_var_36 F_EM_WKLY_MAIN_AD;

	 global ${abbr}_req_37 "HIN14_D19_MTO, HIN14a_D19a_MTO, HIN14b_D19b_MTO, HIN14c_D19c_MTO, HIN14d_D19d_MTO, HIN14e_D19e_MTO: How much did you earn from all your employers before taxes and deductions during [2007/2008]?  final household evaluation";
	 global ${abbr}_var_37 F_IN_HEAD2009;

	 global ${abbr}_req_39 "HIN19a_1_ORIG, H19_1_ORIG: What is the total combined income all members of household during the year [2007/2008]?  final household";
	 global ${abbr}_var_39 F_IN_TOTINC2009;
	 
	 global ${abbr}_req_47 "HIN6_D6_MTO: Are you [or your child/or your children] regularly receiving welfare benefits now?  final household survey";
	 global ${abbr}_var_47 F_IN_TANF_FAM;

	 global ${abbr}_req_168 "final survey sample";
	 global ${abbr}_var_168 F_SVY_SAMPLE2007;

 	global ${abbr}_req_169 "adult survey interview complete";
	 global ${abbr}_var_169 F_SVY_IWCOMPL_AD;

 	global ${abbr}_req_170 "adult survey interview complete";
	 global ${abbr}_var_170 ALLSCH_HIGHGR;

  	global ${abbr}_req_171 "duration weighted - interpolated - Median household income (2009 dollars)";
	 global ${abbr}_var_171 F_C9010T_HHINC_09D_DW;

	 global ${abbr}_req_172 "Duration-wgtd tract share managerial/professional workers";
	 global ${abbr}_var_172 F_C9010T_HISTATUS_DW;
 
 global ${abbr}_req_173 "duration weighted - interpolated - Share black";
	 global ${abbr}_var_173 F_C9010T_PBLACK_DW;
 
 global ${abbr}_req_174 "Duration-weighted tract share college graduates";
	 global ${abbr}_var_174 F_C9010T_PCOLLDEG_DW;
 
 global ${abbr}_req_175 "duration weighted - interpolated - Share employed, civilian";
	 global ${abbr}_var_175 F_C9010T_PEMP_DW;
 
 global ${abbr}_req_176 "F_C9010T_PERPOV_DW	Duration-wgtd tract poverty";
	 global ${abbr}_var_176 F_C9010T_PERPOV_DW;
 
 global ${abbr}_req_177 "duration weighted - interpolated - Share Hispanic";
	 global ${abbr}_var_177 F_C9010T_PHISP_DW;

 global ${abbr}_req_178 "duration weighted - interpolated - Share with more than high";
	 global ${abbr}_var_178 F_C9010T_POVHS_DW;

 global ${abbr}_req_178 "duration weighted - interpolated - Share of families with s";
 global ${abbr}_var_178 F_C9010T_PFSFEM_DW;
 
 global ${abbr}_req_179 "Duration-wgtd tract share minority";
 global ${abbr}_var_179 F_C9010T_PMINORTY_DW;

  global ${abbr}_req_180 "duration weighted - interpolated - Share of households with";
 global ${abbr}_var_180 F_C9010T_PWELF_DW;

;

	 
	 
***********************************;
* INTERIM ADULT ANALYSIS FILE*;
***********************************;	 

global abbr intaad; 
	 
	global ${abbr}_req_34 "D20: During 2001, how much income did you receive from any businesses you have, from work on the side that you did, or from dividends, interest, or rental property you own?  interim household survey";
	 global ${abbr}_var_34 C_HEAD_TOTAL_INCOME C_HH_TOTAL_INCOME;

	global ${abbr}_req_33 "D19, D19a, D19b, D19c, D19d, D19e: How much did you earn from all your employers before taxes and deductions during 2001?  interim household survey";
	 global ${abbr}_var_33 W_EARN_2001_AD ;
	 

***********************************;
* INTERIM CHILD YOUTH ANALYSIS FILE*;
***********************************;	 

global abbr intachyt; 
	 
	global ${abbr}_req_8 "J2: Does child have high school diploma?  interim household survey";
	 global ${abbr}_var_8 E_GRAD_DIPLOMA;
	 
	global ${abbr}_req_9 "J3: Has child received GED?  interim household survey";
	 global ${abbr}_var_9 E_GRAD_GED;
	 
	global ${abbr}_req_10 "J3a: Is [child] currently enrolled in college?  interim household survey";
	 global ${abbr}_var_10 E_ENROL_COLL_PR E_ENROL_COLL_SR E_ENROL_COLL_EVR_PR E_ENROL_COLL_EVR_SR;

	 
	 
***********************************;
* INTERIM ROSTER *;
***********************************;	 

global abbr irawro; 
	 
	global ${abbr}_req_11 "G1m: What is the highest grade of school that [he/she] has ever completed?  interim household survey";
	 global ${abbr}_var_11 G1MX;
	 
	global ${abbr}_req_30 "G2a: Last week, did [member] do any work for pay?  interim household evaluation";
	 global ${abbr}_var_30 C2X G2AX;
	 
	global ${abbr}_req_31 "G2b, G2b1, G2b2, G2b3, G2b4, G2b5: How much did (he/she) earn from all (his/her) employers before taxes and deductions during 2001?  interim household evaluation";
	 global ${abbr}_var_31 G2BX G2B1X G2B2X G2B3X G2B4X G2B5X;
	 
	global ${abbr}_req_32 "G2c: During 2001, how much did (he/she) receive from any businesses he/she has, from work on the side he/she has done, or from dividends, interest, or rental property he/she owns?  interim household evaluation";
	 global ${abbr}_var_32 G2CX;
	 
	global ${abbr}_req_53 "G1l: What is (his/her) marital status?  interim household survey";
	 global ${abbr}_var_53 G1LX;
	 
global abbr none;	 
	 
#delimit cr ;


********************************************
* Create variable lists
********************************************

local countvars = 0
foreach AB in blh blp irawad irawyt frawad frawyt frawro intaad intachyt irawro fina {
	local list`AB' = ""
	foreach NUM of numlist 1/200 {
		if "${`AB'_var_`NUM'}" != "" & "${`AB'_var_`NUM'}" != "unknown" {
			qui di "`NUM'"
			qui di "${`AB'_var_`NUM'}" 
			local list`AB' = strlower("`list`AB'' ${`AB'_var_`NUM'}") 
			local countvars = `countvars' + 1
		}
	}
	global varlist_`AB' " `list`AB''"
	global countvars = `countvars'
	di "`AB' variables are: ${varlist_`AB'}"
}
di $countvars

di "blh list: ${varlist_blh}"
di "blp list: ${varlist_blp}"
di "frawad list: ${varlist_frawad}"
di
di "frawyt list: ${varlist_frawyt}"
di
di "irawad list: ${varlist_irawad}"
di
*di "irawyt list: ${varlist_irawyt}"



********************************************
* Create FAMID crosswalk
********************************************
 
use "$outxwlk2", clear
des, f 

keep famid mto_pseudo_famid
duplicates drop

save "$outfamxwlk", replace



********************************************
* Create Baseline Hhld File
********************************************

clear 
import sas ${arc_blh}, case(lower)

keep famid ${varlist_blh}

merge 1:1 famid using "$outfamxwlk", gen(_mrgfxwlk)
assert _mrgfxwlk == 3
des , f 
drop _mrgfxwlk 

/*
foreach NUM of numlist 1/200 {
	if "${blh_var_`NUM'}" != "" {
		di "${blh_var_`NUM'}"
		note ${blh_var_`NUM'}: ${blh_req_`NUM'}
	}
}
*/

// save with IDs
order famid mto_pseudo_famid ${varlist_blh}
save ${outblh_id}, replace

// save without IDs
drop famid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outblh_pseudo}, replace



********************************************
* Create Baseline Person File
********************************************

clear 
import sas ${arc_blp}, case(lower)

keep ppid famid ${varlist_blp}

merge 1:1 ppid using "$outxwlk2", gen(_mrgxwlk2)
tab _mrgxwlk2
keep if inlist(_mrgxwlk2, 2,3)
assert _mrgxwlk2 == 3
des , f 
drop _mrgxwlk2

// save with IDs
order ppid famid mto_pseudo_id mto_pseudo_famid ${varlist_blp}
save ${outblp_id}, replace

// save without IDs
drop famid
drop ppid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outblp_pseudo}, replace




********************************************
* Create Interim Raw Adult Survey Data
********************************************

di "irawad list: ${varlist_irawad}"
clear 
import sas ${arc_irawad}, case(lower)
gen unknown = .

keep ppid famid ${varlist_irawad}

merge 1:1 ppid using "$outxwlk2", gen(_mrgxwlk2)
tab _mrgxwlk2
keep if inlist(_mrgxwlk2, 3)
des , f 
drop _mrgxwlk2

// save with IDs
order ppid famid mto_pseudo_id mto_pseudo_famid ${varlist_irawad}
save ${outirawad_id}, replace

// save without IDs
drop famid
drop ppid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outirawad_pseudo}, replace



********************************************
* Create Final Raw Adult Survey Data
********************************************

di "frawad list: ${varlist_frawad}"
clear 
import sas ${arc_frawad}, case(lower)

gen unknown = .

keep ppid famid ${varlist_frawad}

merge 1:1 ppid using "$outxwlk2", gen(_mrgxwlk2)
tab _mrgxwlk2
keep if inlist(_mrgxwlk2, 3)
des , f 
drop _mrgxwlk2

// save with IDs
order ppid famid mto_pseudo_id mto_pseudo_famid ${varlist_frawad}
save ${outfrawad_id}, replace

// save without IDs
drop famid
drop ppid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outfrawad_pseudo}, replace


********************************************
* Create Final Raw Youth Survey Data
********************************************

di "frawyt list: ${varlist_frawyt}"
clear 
import sas ${arc_frawyt}, case(lower)

gen unknown = .

keep ppid famid ${varlist_frawyt}

merge 1:1 ppid using "$outxwlk2", gen(_mrgxwlk2)
tab _mrgxwlk2
keep if inlist(_mrgxwlk2, 3)
des , f 
drop _mrgxwlk2

// save with IDs
order ppid famid mto_pseudo_id mto_pseudo_famid ${varlist_frawayt}
save ${outfrawyt_id}, replace

// save without IDs
drop famid
drop ppid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outfrawyt_pseudo}, replace


********************************************
* Create Final Roster Data
********************************************

di "frawro list: ${varlist_frawro}"
clear 
import sas ${arc_frawro}, case(lower)

gen unknown = .

keep ppid famid ${varlist_frawro}

merge 1:1 ppid using "$outxwlk2", gen(_mrgxwlk2)
tab _mrgxwlk2
keep if inlist(_mrgxwlk2, 3)
des , f 
drop _mrgxwlk2

// save with IDs
order ppid famid mto_pseudo_id mto_pseudo_famid ${varlist_frawaro}
save ${outfrawro_id}, replace

// save without IDs
drop famid
drop ppid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outfrawro_pseudo}, replace


********************************************
* Create Interim Roster Data
********************************************

di "irawro list: ${varlist_irawro}"
clear 
import sas ${arc_irawro}, case(lower)

gen unknown = .

keep ppid famid ${varlist_irawro}

merge 1:1 ppid using "$outxwlk2", gen(_mrgxwlk2)
tab _mrgxwlk2
keep if inlist(_mrgxwlk2, 3)
des , f 
drop _mrgxwlk2

// save with IDs
order ppid famid mto_pseudo_id mto_pseudo_famid ${varlist_irawaro}
save ${outirawro_id}, replace

// save without IDs
drop famid
drop ppid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outirawro_pseudo}, replace


********************************************
* Create Interim Adult Analysis Data
********************************************

di "intaad list: ${varlist_intaad}"
clear 
import sas ${arc_intaad}, case(lower)

gen unknown = .

keep ppid famid wt_totsvy ${varlist_intaad}

merge 1:1 ppid using "$outxwlk2", gen(_mrgxwlk2)
tab _mrgxwlk2
keep if inlist(_mrgxwlk2, 3)
des , f 
drop _mrgxwlk2

// save with IDs
order ppid famid mto_pseudo_id mto_pseudo_famid wt_totsvy ${varlist_intaad}
save ${outintaad_id}, replace

// save without IDs
drop famid
drop ppid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outintaad_pseudo}, replace


********************************************
* Create Interim Child Youth Analysis Data
********************************************

di "intachyt list: ${varlist_intachyt}"
clear 
import sas ${arc_intachyt}, case(lower)

gen unknown = .

keep ppid famid wt_totsvy wt_totpocy ${varlist_intachyt}

merge 1:1 ppid using "$outxwlk2", gen(_mrgxwlk2)
tab _mrgxwlk2
keep if inlist(_mrgxwlk2, 3)
des , f 
drop _mrgxwlk2

// save with IDs
order ppid famid mto_pseudo_id mto_pseudo_famid wt_totsvy wt_totpocy ${varlist_intachyt}
save ${outintachyt_id}, replace

// save without IDs
drop famid
drop ppid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outintachyt_pseudo}, replace


********************************************
* Create Final Analysis Data
********************************************

di "fina list: ${varlist_fina}"
clear 
import sas ${arc_fina}, case(lower)

keep ppid famid f_svy_sample2007 f_svy_yob_imp f_wt_totcore98 f_wt_totcore f_wt_totsvy f_wt_totsvy_ad f_wt_tothpy x_* ${varlist_fina}

rename f_svy_yob_imp f_svy_yob_imp_ytgc
replace f_svy_yob_imp_ytgc = . if !inlist(f_svy_sample2007, "YT", "GC", "EY")
sum f_svy_yob_imp_ytgc

merge 1:1 ppid using "$outxwlk2", gen(_mrgxwlk2)
tab _mrgxwlk2
keep if inlist(_mrgxwlk2, 3)
des , f 
drop _mrgxwlk2

// save with IDs
order ppid famid mto_pseudo_id mto_pseudo_famid f_svy* f_wt* x_* ${varlist_fina}
save ${outfina_id}, replace

// save without IDs
drop famid
drop ppid
cap sum ppid
cap sum famid
cap sum *dob*
save ${outfina_pseudo}, replace


*******************
* STACK AND CHECK *
*******************
*irawyt - not used

clear
use ${outblh_pseudo}
gen str10 abbreviation = "blh"
foreach ABBR in blp irawad  frawad frawyt frawro intaad intachyt irawro fina {
	append using ${out`ABBR'_pseudo}
	replace abbreviation = "`ABBR'" if mi(abbreviation) 
}

assert !mi(mto_pseudo_famid)

tab abbreviation if mi(mto_pseudo_id)
tab abbreviation


*******************
* LIST CONTENTS *
*******************

foreach ABBR in blh blp irawad  frawad frawyt frawro intaad intachyt irawro fina {
	di
	di "==============================================="
	di 
	use ${out`ABBR'_pseudo}, clear
	des , f
}

log close


